home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / PatFrame.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.1 KB  |  200 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                PatFrame.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef PATFRAME_H
  15. #include "PatFrame.h"
  16. #endif
  17.  
  18. #ifndef DRAWPART_H
  19. #include "DrawPart.h"
  20. #endif
  21.  
  22. #ifndef DEFINES_K
  23. #include "Defines.k"
  24. #endif
  25.  
  26. // ----- Part Layer -----
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWCONTXT_H
  33. #include "FWContxt.h"
  34. #endif
  35.  
  36. // ----- OS Layer -----
  37.  
  38. #ifndef FWWINDOW_H
  39. #include "FWWindow.h"
  40. #endif
  41.  
  42. #ifndef FWMEMMGR_H
  43. #include "FWMemMgr.h"
  44. #endif
  45.  
  46. #ifndef FWEVENT_H
  47. #include "FWEvent.h"
  48. #endif
  49.  
  50. #ifndef FWCOLOR_H
  51. #include "FWColor.h"
  52. #endif
  53.  
  54. #ifndef FWRECSHP_H
  55. #include "FWRecShp.h"
  56. #endif
  57.  
  58. //========================================================================================
  59. // Runtime Informations
  60. //========================================================================================
  61.  
  62. #ifdef FW_BUILD_MAC
  63. #pragma segment odfdrawframes
  64. #endif
  65.  
  66. //========================================================================================
  67. // CLASS CPatternChangedInterest
  68. //========================================================================================
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // CPatternChangedInterest::CPatternChangedInterest
  72. //----------------------------------------------------------------------------------------
  73.  
  74. CPatternChangedInterest::CPatternChangedInterest(FW_MNotifier* notifier) :
  75.     FW_CInterest(notifier, kPatternChanged)
  76. {
  77. }
  78.  
  79. //----------------------------------------------------------------------------------------
  80. // CPatternChangedInterest::~CPatternChangedInterest
  81. //----------------------------------------------------------------------------------------
  82.  
  83. CPatternChangedInterest::~CPatternChangedInterest()
  84. {
  85. }
  86.  
  87. //========================================================================================
  88. // CLASS CPatternChangedNotification
  89. //========================================================================================
  90.  
  91. //----------------------------------------------------------------------------------------
  92. // CPatternChangedNotification::CPatternChangedNotification
  93. //----------------------------------------------------------------------------------------
  94.  
  95. CPatternChangedNotification::CPatternChangedNotification(const FW_CInterest& interest, 
  96.                                                         short patternIndex, 
  97.                                                         FW_ERenderVerbs renderVerb) :
  98.     FW_CNotification(interest),
  99.     fPatternIndex(patternIndex),
  100.     fRenderVerb(renderVerb)
  101. {
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. // CPatternChangedNotification::~CPatternChangedNotification
  106. //----------------------------------------------------------------------------------------
  107.  
  108. CPatternChangedNotification::~CPatternChangedNotification()
  109. {
  110. }
  111.  
  112. //========================================================================================
  113. // CLASS CPatternFrame
  114. //========================================================================================
  115.  
  116. FW_DEFINE_AUTO(CPatternFrame)
  117.     
  118. //----------------------------------------------------------------------------------------
  119. // CPatternFrame::CPatternFrame
  120. //----------------------------------------------------------------------------------------
  121.  
  122. CPatternFrame::CPatternFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, CDrawPart* drawPart) :
  123.     CFloatingWindowFrame(ev, odFrame, presentation, drawPart),
  124.     FW_MNotifier(),
  125.     fGrid(2, 6, FW_CPoint(FW_IntToFixed(2), FW_IntToFixed(2)), FW_CPoint(kPatternCellSize, kPatternCellSize), FW_kFixedPos1),
  126.     fDrawPart(drawPart)
  127. {
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // CPatternFrame::~CPatternFrame
  132. //----------------------------------------------------------------------------------------
  133.  
  134. CPatternFrame::~CPatternFrame()
  135. {
  136. }
  137.  
  138. //----------------------------------------------------------------------------------------
  139. //    CPatternFrame::Draw
  140. //----------------------------------------------------------------------------------------
  141.  
  142. void CPatternFrame::Draw(Environment* ev, ODFacet* odFacet, ODShape* invalidShape)
  143. {
  144.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  145.     vc.SetMapping(fMapping);
  146.  
  147.     EraseBackground(ev, vc);
  148.  
  149.     //    ----- Draw the grid -----
  150.     fGrid.DrawGridBorders(vc);
  151.     
  152.     // ----- Draw each color -----
  153.     FW_CRect rect;
  154.     FW_CRectShape rectShape(FW_kZeroRect, FW_kFill);
  155.     for (unsigned long index = 0; index < 12; index++)
  156.     {
  157.         fGrid.GetCellInterior(index, rect);
  158.         rectShape.SetRectangle(rect);
  159.         rectShape.GetStyle().SetPattern(fDrawPart->GetPattern(index));
  160.         rectShape.Render(vc);
  161.     }
  162. }
  163.  
  164. //----------------------------------------------------------------------------------------
  165. //    CPatternFrame::DoMouseDown
  166. //----------------------------------------------------------------------------------------
  167.  
  168. FW_Handled CPatternFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  169. {
  170.     FW_CPoint where = theMouseEvent.GetLogicalMousePosition(ev, fMapping);
  171.     
  172.     unsigned long patIndex;    
  173.     if (fGrid.FindCell(where, patIndex))
  174.     {
  175.         CPatternChangedInterest interest(this);
  176.         CPatternChangedNotification notification(interest, patIndex, theMouseEvent.IsCopyModifier(ev) ? FW_kFrame : FW_kFill);
  177.         Notify(ev, notification);
  178.     }
  179.  
  180.     return FW_kHandled;
  181. }
  182.  
  183. //----------------------------------------------------------------------------------------
  184. // CPatternFrame::FacetAdded
  185. //----------------------------------------------------------------------------------------
  186.  
  187. void CPatternFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  188. {
  189.     // ----- Call inherited first -----
  190.     CFloatingWindowFrame::FacetAdded(ev, facet, facetCount);
  191.     
  192.     // ----- Resize my Window -----
  193.     FW_CRect gridRect;
  194.     fGrid.GetExteriorGridRect(gridRect);
  195.     gridRect.Inset(-FW_IntToFixed(2), -FW_IntToFixed(2));
  196.     FW_CPoint windowSize(gridRect.Width(), gridRect.Height());
  197.     GetWindow(ev)->SetWindowSize(ev, windowSize);
  198. }
  199.  
  200.